//
//  DealView.m
//  ACSProduct
//
//  Created by Rohit Dhawan on 14/05/12.
//  Copyright (c) 2012 dhillon. All rights reserved.
//

#import "DealView.h"

@implementation DealView

@synthesize webOfferView,labelExpDate,labelDDDB,scrlViewDeal,pgCtrlDeal,zoomView,clientDeal;


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

-(void)setview:(NSString *)string
{
    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = self.bounds;
    
    CGColorRef topColor = [[UIColor colorWithRed:((float)252)/256 green:((float)248)/256 blue:((float)249)/256 alpha:1.0] CGColor];
    CGColorRef bottomColor = [[UIColor colorWithRed:((float)195)/256 green:((float)195)/256 blue:((float)195)/256 alpha:1.0] CGColor];
    gradient.colors = [NSArray arrayWithObjects:(id)topColor, (id)bottomColor, nil];
    
    
    
    [self.layer insertSublayer:gradient atIndex:0];

    
    [webOfferView loadHTMLString:[NSString stringWithFormat:@"<font size='2' face='Helvetica'>%@</font>",string]
                         baseURL:nil];
    
}

//;

-(void)loadImageInScrollView:(NSMutableArray *)arrayImages
{
    self.scrlViewDeal.pagingEnabled = YES;
    
    int incX = self.webOfferView.frame.origin.x+self.webOfferView.frame.size.width;
    
    
    [self.scrlViewDeal setContentSize:CGSizeMake(([arrayImages count]+1)*(webOfferView.frame.size.width),240)];
//    self.scrlViewDeal.scrollEnabled = NO;
//    
    
    NSLog(@"%@",arrayImages);

    for (int i=0; i<[arrayImages  count]; i++) 
    { 
        imagVen = [[VenDealImageView alloc] initWithFrame:CGRectMake(incX, 0, self.scrlViewDeal.frame.size.width,240)];
        imagVen.client= self;
        imagVen.tag = i;
        
        imagVen.imageVenDeal.placeholderImage = [UIImage imageNamed:@"PlaceHolder.png"];
        [imagVen setviewWithUrl:[NSURL  URLWithString:[arrayImages objectAtIndex:i]]];
        
        [self.scrlViewDeal addSubview:imagVen];
        incX += (self.webOfferView.frame.origin.x+self.webOfferView.frame.size.width);
        [imagVen  release];
    }
   
    self.pgCtrlDeal.currentPage = 0;
    self.pgCtrlDeal.numberOfPages =[arrayImages count]+1;
    
//     [self.scrlViewDeal setContentSize:CGSizeMake(([arrayImages count]+1)*(webOfferView.frame.size.width),200)];
}

-(void)doubleTouch:(NSInteger)tag
{
    [clientDeal touchAtTag:tag];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/
-(void)setPageControlDeal
{
    
}
#pragma mark- UIScrollview Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{
    CGFloat pageWidth = scrollView.frame.size.width;
    float fractionalPage = scrollView.contentOffset.x / pageWidth;
    NSInteger page = lround(fractionalPage);
    self.pgCtrlDeal.currentPage = page; 
}
   
@end
